package com.example.demo;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 张成
 * @version 1.0
 * @date 2022/3/8 11:06
 */
public class ServerInfo extends GenericServlet {

    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=gbk");
        PrintWriter out = response.getWriter();
        ServletContext sc = getServletContext();
        out.println("<html>");
        out.println("<body>");
        out.println("<head>");
        out.println("<title>获取服务器端信息</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h2>服务器端信息：</h2>");
        out.println("<table width=\"500\" border=\"1\">");
        out.println("<tr>");
        out.println("<td width=\"140\">站点名</td>");
        out.println("<td width=\"360\">" + request.getServerName()
                + "</td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td>端口号</td>");
        out.println("<td>" + request.getServerPort() + "</td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td>服务器类型</td>");
        out.println("<td>" + sc.getServerInfo() + "</td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td>支持Servlet版本</td>");
        out.println("<td>" + sc.getMajorVersion() + "."
                + sc.getMinorVersion() + "</td>");
        out.println("</tr>");
        out.println("</table>");
        out.println("</body>");
        out.println("</html>");
    }
}
